package com.cskaoyan.javase.homework.primary._1method.basic;

import java.util.Scanner;

/**
 * @description: 根据键盘录入打印nn乘法表
 * @author: wuguidong@cskaoyan.onaliyun.com
 **/

/**
 * 根据键盘录入打印nn乘法表，n是可变的
 * 打印乘法表实际上和打印m行n列的井号没有本质区别
 * 1 * 1 = 1
 * 1 * 2 = 2	2 * 2 = 4
 * 1 * 3 = 3	2 * 3 = 6	3 * 3 = 9
 * 1 * 4 = 4	2 * 4 = 8	3 * 4 = 12	4 * 4 = 16
 *
 */
public class MultiplicationTablesDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个int参数作为乘法表的阶数:");
        int x = sc.nextInt();

        // 调用方法
        printTable(x);
    }

    public static void printTable(int n) {
        // 打印n行n列的乘法列
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j + " * " + i + " = " + (i * j) + '\t');
            }
            System.out.println();
        }
    }
}
